package com.itye.com;

import java.util.Random;

public class ClassRoom {
    private String className;
    private Group[] groups;
    private Student[] students;

    public ClassRoom(String className) {
        this.className = className;
        groups = new Group[0];
        students = new Student[0];
    }

    public void addGroup(Group group) {
        Group[] newArray = new Group[groups.length + 1];
        System.arraycopy(groups, 0, newArray, 0, groups.length);
        newArray[groups.length] = group;
        groups = newArray;
    }

    public void addStudent(Student student) {
        Student[] newArray = new Student[students.length + 1];
        System.arraycopy(students, 0, newArray, 0, students.length);
        newArray[students.length] = student;
        students = newArray;
    }

    public Group getRandomGroup() {
        if (groups.length == 0) {
            return null;
        }
        Random random = new Random();
        int randomIndex = random.nextInt(groups.length);
        return groups[randomIndex];
    }

    public Student getRandomStudentFromClass() {
        if (students.length == 0) {
            return null;
        }
        Random random = new Random();
        int randomIndex = random.nextInt(students.length);
        return students[randomIndex];
    }
}
